<?php

namespace app\common\model\mysql;

use think\Model;

class OrderBackBucket extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'or_order_back_bucket';

    /**
     * 查询配送订单回桶数据列表
     * @param array $where
     * @param string $field
     * @return OrderProductWater[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getNormalBackBucket(array $where = [], string $field = "*"){
        $order = [
            "id" =>"asc",
        ];
        $result = $this->where($where)->field($field)->order($order)->select();
        return $result->toArray();
    }

    /**
     * 新增配送订单回桶数据列表
     * @param $data
     * @return \think\Collection
     * @throws \Exception
     */
    public function addAllBackBucket($data){
        return $this->saveAll($data);
    }

    /**
     * 删除配送订单回桶数据列表
     * @param $where
     * @return bool
     */
    public function deleteAllNormalBackBucket($where){
        return $this->where($where)->delete();
    }

    /**
     * 查询订单回桶总量
     * @param array $where
     * @param string $field
     * @return float
     */
    public function getNormalBackBucketSum(array $where = [], string $field = "sellcount"){
        $result = $this->where($where)->sum($field);
        return $result;
    }
}
